package com.tiancheng.onecode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tiancheng.onecode.entity.PlatformMerchant;
import com.tiancheng.onecode.exception.Asserts;
import com.tiancheng.onecode.mapper.PlatformMerchantMapper;
import com.tiancheng.onecode.service.IPlatformMerchantService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @Author: kellen
 * @Description:
 * @Date: create in 2024/12/13 10:44
 */
@Service
public class PlatformMerchantServiceImpl extends ServiceImpl<PlatformMerchantMapper, PlatformMerchant> implements IPlatformMerchantService {

    @Override
    public Boolean newPlatformMerchant(PlatformMerchant entity) {
        final long count = this.count(new LambdaQueryWrapper<PlatformMerchant>().eq(PlatformMerchant::getPlatformCode, entity.getPlatformCode()).eq(PlatformMerchant::getMerchantCode, entity.getMerchantCode()));
        Asserts.isTrue(count==0,"不允许重复添加商户！");
        entity.setCreatedDt(LocalDateTime.now());
        return this.save(entity);
    }
}
